$(document)
		.ready(
				function(){
					
					selectOperationControl();
				});

function selectOperationControl(){
	// 遍历添加事件
	 $.each($("input[id^=operationCodeShow]"),function(i,item) {
			var basePath = $("#basePath").val();
			$(item).keyup(function(event) {
						var selectId = $(item).attr("id");
						var selectRealId = "";
						// 获取后面的id
						if (selectId.indexOf("-") != -1) {
							selectRealId = selectId.split("-")[1];
						}
						var jq_search_suggest = $("#operationCodeDiv"
								+ selectRealId);
									var pinyinReg = /^[a-zA-Z]*$/;
									var bianhaoReg = /^[a-zA-Z]\d*.?\d*$/;
									var bianhaoReg2 = /^\d*.?\d*$/;
									var getVal = item.value;
									if (getVal
											&& getVal.length > 1) {
										var type = 4;
										if (pinyinReg
												.exec(getVal)) {
											// 拼音的时候
											type = 1;
											getVal = getVal
													.toUpperCase();
										} else if (bianhaoReg
												.exec(getVal)
												|| bianhaoReg2
														.exec(getVal)) {
											// 编号时
											getVal = getVal
													.toUpperCase();
											type = 3;
										} else {
											// 其他情况
											type = 2;
										}
										// 获取诊断类型
										/*var zdlx = $(
												"#idzdtype-"
														+ selectRealId
														+ " option:selected")
												.val();
										if (!zdlx) {
											zdlx = $(
													"#getzdtypeForGuDing"
															+ selectRealId)
													.val();
										}
										if (!zdlx) {
											alert("请选择诊断类型");
											return;
										}*/
										// ///////病理号
										/*if (zdlx == 44
												&& getVal
														.indexOf('M') != -1) {
											var bingliInputId = "#bingliInputVal-"
													+ selectRealId;
											var bingliDivId = "#bingliDiv-"
													+ selectRealId;
											var jq_binglidiv = $(bingliDivId);
											jq_binglidiv
													.empty();
											createBingliHaoInput(
													selectRealId)
													.appendTo(
															jq_binglidiv);

										}*/
										if (getVal.length > 1) {
											$
													.post(
															basePath+'/baseinfo/queryOperation',
															{
																queryValueType : type,
																queryValue : getVal
															},
															function(
																	data) {
																if (typeof (data) == "string") {
																	alert(data);
																	return false;
																}
																jq_search_suggest
																		.empty();
																xunhuanZiDian2(
																		data,
																		jq_search_suggest);
																// /////////////////////////////////////下按事件

																jq_search_suggest
																		.addClass(
																				"divscroll300 search_suggest")
																		.show();
																$(
																		"#operationCode"
																				+ selectRealId)
																		.val(
																				"");
																$("#operationName"+ selectRealId).val("");
															},
															'json');
										} else {
											$(
													"#operationCode"
															+ selectRealId)
													.val("");
											$("#operationName"+ selectRealId).val("");
											jq_search_suggest
													.hide();
										}
									} else {
										$(
												"#operationCode"
														+ selectRealId)
												.val("");
										$("#operationName"+ selectRealId).val("");
										jq_search_suggest
												.hide();
									}
									function xunhuanZiDian2(
											data, com) {
										com.empty();
										
										var rowNum = 1;
										for ( var index in data) {
											var Obj = data[index];
											var code = Obj.code;
											var name = Obj.name;
											
											var opt = $("<div>")
													.attr(
															'code',
															code).attr('name',name)
													.text(
															code
																	+ "-"
																	+ name)
													.addClass(
															"suggest_link");
											opt
													.mouseover(
															function() {
																var divOpts = $("div[rowNum][ck='ck']");
																divOpts
																		.attr(
																				"ck",
																				"");
																$(
																		this)
																		.addClass(
																				"suggest_link_over")
																		.attr(
																				"ck",
																				"ck");

															})
													.mouseout(
															function() {
																$(
																		"div[rowNum][ck]")
																		.removeClass(
																				"suggest_link_over");
																;
																$(
																		this)
																		.removeClass(
																				"suggest_link_over");
																$(
																		this)
																		.addClass(
																				"suggest_link");
															})
													.click(
															function() {
																var zhuyaozhenduanError = new Array();
																// 获取值
																var selectDivObj = $(this);
																var code = selectDivObj
																		.attr("code");
																var text = selectDivObj
																		.text();
																var name = selectDivObj.attr("name");
																// 赋值
																$(
																		"#operationCode"
																				+ selectRealId)
																		.val(
																				code);
																$("#operationName"+ selectRealId).val(name);
															
																$(
																		"#operationCodeShow-"
																				+ selectRealId)
																		.val(
																				text);
																$(
																		"#operationCodeShow-"
																				+ selectRealId)
																		.focus();
																
																
																// //////////////判断逻辑end////////////////
																
																
																// 隐藏显示层
																jq_search_suggest
																		.hide();
															});
											com.append(opt);
										}
									}
								});
						// ////////////////////////////编码制空---------2014-01-24
						$(item)
								.blur(function() {
									var thisInput = $(this);
									var shiVal = thisInput
											.val();
								});
					});
	// ///////////////////////////////////////////////////////////////////


}

function changeOperation(){
	/**手术操作*/
	var opeCount = $("#operationCount").val();
	for(var i=0;i<opeCount;i++){
		(function(i){
			$("select[name='operations["+i+"].opsAfterSyndromeId']").change(function(){
				if($("select[name='operations["+i+"].opsAfterSyndromeId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsAfterSyndromeId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsAfterSyndromeName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsAfterSyndromeName']").val("");
				}
			});
			$("select[name='operations["+i+"].incisionLevelId']").change(function(){
				if($("select[name='operations["+i+"].incisionLevelId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].incisionLevelId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].incisionLevelName']").val(name);
				}else{
					$("input[name='operations["+i+"].incisionLevelName']").val("");
				}
			});
			$("select[name='operations["+i+"].cicatrizationTypeId']").change(function(){
				if($("select[name='operations["+i+"].cicatrizationTypeId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].cicatrizationTypeId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].cicatrizationTypeName']").val(name);
				}else{
					$("input[name='operations["+i+"].cicatrizationTypeName']").val("");
				}
			});
			
			$("select[name='operations["+i+"].opsPerationMarkId']").change(function(){
				if($("select[name='operations["+i+"].opsPerationMarkId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsPerationMarkId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsPerationMarkName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsPerationMarkName']").val("");
				}
				
			});
			$("select[name='operations["+i+"].opsTimeLimitId']").change(function(){
				if($("select[name='operations["+i+"].opsTimeLimitId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsTimeLimitId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsTimeLimitName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsTimeLimitName']").val("");
				}
				
			});
			
			$("select[name='operations["+i+"].opsLevelId']").change(function(){
				if($("select[name='operations["+i+"].opsLevelId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsLevelId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsLevelName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsLevelName']").val("");
				}
				
			});
			$("select[name='operations["+i+"].opsCharacterId']").change(function(){
				if($("select[name='operations["+i+"].opsCharacterId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsCharacterId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsCharacterName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsCharacterName']").val("");
				}
				
			});
			
			$("select[name='operations["+i+"].opsPartId']").change(function(){
				if($("select[name='operations["+i+"].opsPartId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsPartId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsPartName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsPartName']").val("");
				}
				
			});
			$("select[name='operations["+i+"].opsInfectPartId']").change(function(){
				if($("select[name='operations["+i+"].opsInfectPartId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsInfectPartId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsInfectPartName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsInfectPartName']").val("");
				}
				
			});
			
			$("select[name='operations["+i+"].anaesthesiaLevelId']").change(function(){
				if($("select[name='operations["+i+"].anaesthesiaLevelId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].anaesthesiaLevelId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].anaesthesiaLevelName']").val(name);
				}else{
					$("input[name='operations["+i+"].anaesthesiaLevelName']").val("");
				}
				
			});
			$("select[name='operations["+i+"].anaesthesiaTypeId']").change(function(){
				if($("select[name='operations["+i+"].anaesthesiaTypeId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].anaesthesiaTypeId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].anaesthesiaTypeName']").val(name);
				}else{
					$("input[name='operations["+i+"].anaesthesiaTypeName']").val("");
				}
				
			});
			
			$("select[name='operations["+i+"].opsAfterDirectionId']").change(function(){
				if($("select[name='operations["+i+"].opsAfterDirectionId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsAfterDirectionId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsAfterDirectionName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsAfterDirectionName']").val("");
				}
				
			});
			
			
			$("select[name='operations["+i+"].opsNisLevelId']").change(function(){
				if($("select[name='operations["+i+"].opsNisLevelId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].opsNisLevelId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].opsNisLevelName']").val(name);
				}else{
					$("input[name='operations["+i+"].opsNisLevelName']").val("");
				}
				
			});
			
			$("select[name='operations["+i+"].anaesthesiaUnforeseenId']").change(function(){
				
				if($("select[name='operations["+i+"].anaesthesiaUnforeseenId'] option:selected").val()!=""){
					var name=$("select[name='operations["+i+"].anaesthesiaUnforeseenId'] option:selected").text().split("-")[1];
					$("input[name='operations["+i+"].anaesthesiaUnforeseenName']").val(name);
				}else{
					$("input[name='operations["+i+"].anaesthesiaUnforeseenName']").val("");
				}
				
			});
		})(i);
	}
}

